package org.web.locks.databasedistributedlocks.sdk.dto;

import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.io.Serializable;

@Setter
@Getter
public class TryLockDTO implements Serializable, LockConstants {

    private static final long serialVersionUID = 1L;

    public TryLockDTO(@NotEmpty(message = "锁标记不能为空")
                      @Size(max = MAX_LOCK_MARKER_LENGTH, message = "锁标记不能超过{" + MAX_LOCK_MARKER_LENGTH + "}个字符")
                      String lockMarker,
                      @Max(value = MAX_LOCK_EXPIRE_TIME, message = "设置锁定的最长时间不能超过{" + MAX_LOCK_EXPIRE_TIME + "}毫秒，即5分钟")
                      @Min(value = MIN_LOCK_EXPIRE_TIME, message = "设置锁定的时间不能小于{" + MIN_LOCK_EXPIRE_TIME + "}毫秒")
                      Integer lockExpireTime,
                      @Size(max = MAX_LOCK_OWNER_LENGTH, message = "锁拥有者标识，不能超过{" + MAX_LOCK_OWNER_LENGTH + "}个字符")
                      String lockOwner,
                      @Max(value = MAX_TRY_LOCK_TIMEOUT, message = "设置获取锁的超时时间不能超过{" + MAX_TRY_LOCK_TIMEOUT + "}毫秒，即5分钟")
                      @Min(value = MIN_TRY_TIMEOUT, message = "设置获取锁的超时时间不能小于{" + MIN_TRY_TIMEOUT + "}毫秒")
                      Long tryTimeout,
                      @Max(value = MAX_TRY_COUNT, message = "尝试次数不能超过" + MAX_TRY_COUNT)
                      @Min(value = DEFAULT_TRY_COUNT, message = "尝试次数不能小于" + DEFAULT_TRY_COUNT)
                      Integer tryCount) {
        this.lockDTO = new LockDTO(lockMarker, lockExpireTime, lockOwner);
        this.tryTimeout = tryTimeout;
        this.tryCount = tryCount;
    }

    private LockDTO lockDTO;

    private boolean success = false;

    private Long tryTimeout;

    private Integer tryCount;
}
